
package com.micro.school.system.convert.student;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.micro.school.system.domain.StudentInfo;
import com.micro.school.system.domain.vo.StudentInfoVo;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.stream.Collectors;

@Mapper
public interface StudentInfoConvert {

    /**
     * 将 StudentInfoVo 转换为 StudentInfo
     *
     * @param vo StudentInfoVo 对象
     * @return StudentInfo 对象
     */
    public static StudentInfo convertToInfo(StudentInfoVo vo) {
        if (vo == null) {
            return null;
        }

        StudentInfo info = new StudentInfo();

        // 基本属性转换
        info.setId(vo.getId());
        info.setName(vo.getName());
        info.setSex(vo.getSex());
        info.setIdNumber(vo.getIdNumber());
        info.setSchoolId(vo.getSchoolId());
        info.setSchoolName(vo.getSchoolName());
        info.setCollegeId(vo.getCollegeId());
        info.setCollegeName(vo.getCollegeName());
        info.setEducation(vo.getEducation());
        info.setMajorId(vo.getMajorId());
        info.setMajorName(vo.getMajorName());
        info.setGradeId(vo.getGradeId());
        info.setGradeName(vo.getGradeName());
        info.setClassId(vo.getClassId());
        info.setClassName(vo.getClassName());
        info.setSchoolSystem(vo.getSchoolSystem());
        info.setSignTime(vo.getSignTime());
        info.setSignStatus(vo.getSignStatus());
        info.setGraduate(vo.getGraduate());
        info.setPhone(vo.getPhone());
        info.setOutMsg(vo.getOutMsg());
        info.setOutDate(vo.getOutDate());
        info.setSealStatus(vo.getSealStatus());
        info.setSealTime(vo.getSealTime());
        info.setTenantId(vo.getTenantId());
        info.setEducationId(vo.getEducationId());
        info.setIsDel(vo.getIsDel());
        info.setCompusId(vo.getCompusId());
        info.setBranchName(vo.getBranchName());

        // 继承自BaseEntity的属性（如果需要）
        // info.setCreateTime(vo.getCreateTime());
        // info.setUpdateTime(vo.getUpdateTime());

        return info;
    }

    /**
     * 将 StudentInfo 转换为 StudentInfoVo
     *
     * @param info StudentInfo 对象
     * @return StudentInfoVo 对象
     */
    public static StudentInfoVo convertToVo(StudentInfo info) {
        if (info == null) {
            return null;
        }

        StudentInfoVo vo = new StudentInfoVo();

        // 基本属性转换
        vo.setId(info.getId());
        vo.setName(info.getName());
        vo.setSex(info.getSex());
        vo.setIdNumber(info.getIdNumber());
        vo.setSchoolId(info.getSchoolId());
        vo.setSchoolName(info.getSchoolName());
        vo.setCollegeId(info.getCollegeId());
        vo.setCollegeName(info.getCollegeName());
        vo.setEducation(info.getEducation());
        vo.setMajorId(info.getMajorId());
        vo.setMajorName(info.getMajorName());
        vo.setGradeId(info.getGradeId());
        vo.setGradeName(info.getGradeName());
        vo.setClassId(info.getClassId());
        vo.setClassName(info.getClassName());
        vo.setSchoolSystem(info.getSchoolSystem());
        vo.setSignTime(info.getSignTime());
        vo.setSignStatus(info.getSignStatus());
        vo.setGraduate(info.getGraduate());
        vo.setPhone(info.getPhone());
        vo.setOutMsg(info.getOutMsg());
        vo.setOutDate(info.getOutDate());
        vo.setSealStatus(info.getSealStatus());
        vo.setSealTime(info.getSealTime());
        vo.setTenantId(info.getTenantId());
        vo.setEducationId(info.getEducationId());
        vo.setIsDel(info.getIsDel());
        vo.setCompusId(info.getCompusId());
        vo.setBranchName(info.getBranchName());

        return vo;
    }

    /**
     * 将 StudentInfoVo 列表转换为 StudentInfo 列表
     *
     * @param voList StudentInfoVo 对象列表
     * @return StudentInfo 对象列表
     */
    public static List<StudentInfo> convertToInfoList(List<StudentInfoVo> voList) {
        if (voList == null) {
            return null;
        }

        return voList.stream()
                .map(StudentInfoConvert::convertToInfo)
                .collect(Collectors.toList());
    }

    /**
     * 将 StudentInfo 列表转换为 StudentInfoVo 列表
     *
     * @param infoList StudentInfo 对象列表
     * @return StudentInfoVo 对象列表
     */
    public static List<StudentInfoVo> convertToVoList(List<StudentInfo> infoList) {
        if (infoList == null) {
            return null;
        }

        return infoList.stream()
                .map(StudentInfoConvert::convertToVo)
                .collect(Collectors.toList());
    }

    /**
     * 更新 StudentInfo 对象的属性（部分更新）
     *
     * @param info 要更新的 StudentInfo 对象
     * @param vo 包含新值的 StudentInfoVo 对象
     */
    public static void updateInfoFromVo(StudentInfo info, StudentInfoVo vo) {
        if (info == null || vo == null) {
            return;
        }

        if (vo.getName() != null) {
            info.setName(vo.getName());
        }
        if (vo.getSex() != null) {
            info.setSex(vo.getSex());
        }
        if (vo.getIdNumber() != null) {
            info.setIdNumber(vo.getIdNumber());
        }
        if (vo.getSchoolId() != null) {
            info.setSchoolId(vo.getSchoolId());
        }
        if (vo.getSchoolName() != null) {
            info.setSchoolName(vo.getSchoolName());
        }
        if (vo.getCollegeId() != null) {
            info.setCollegeId(vo.getCollegeId());
        }
        if (vo.getCollegeName() != null) {
            info.setCollegeName(vo.getCollegeName());
        }
        if (vo.getEducation() != null) {
            info.setEducation(vo.getEducation());
        }
        if (vo.getMajorId() != null) {
            info.setMajorId(vo.getMajorId());
        }
        if (vo.getMajorName() != null) {
            info.setMajorName(vo.getMajorName());
        }
        if (vo.getGradeId() != null) {
            info.setGradeId(vo.getGradeId());
        }
        if (vo.getGradeName() != null) {
            info.setGradeName(vo.getGradeName());
        }
        if (vo.getClassId() != null) {
            info.setClassId(vo.getClassId());
        }
        if (vo.getClassName() != null) {
            info.setClassName(vo.getClassName());
        }
        if (vo.getSchoolSystem() != null) {
            info.setSchoolSystem(vo.getSchoolSystem());
        }
        if (vo.getSignTime() != null) {
            info.setSignTime(vo.getSignTime());
        }
        if (vo.getSignStatus() != null) {
            info.setSignStatus(vo.getSignStatus());
        }
        if (vo.getGraduate() != null) {
            info.setGraduate(vo.getGraduate());
        }
        if (vo.getPhone() != null) {
            info.setPhone(vo.getPhone());
        }
        if (vo.getOutMsg() != null) {
            info.setOutMsg(vo.getOutMsg());
        }
        if (vo.getOutDate() != null) {
            info.setOutDate(vo.getOutDate());
        }
        if (vo.getSealStatus() != null) {
            info.setSealStatus(vo.getSealStatus());
        }
        if (vo.getSealTime() != null) {
            info.setSealTime(vo.getSealTime());
        }
        if (vo.getTenantId() != 0) {
            info.setTenantId(vo.getTenantId());
        }
        if (vo.getEducationId() != null) {
            info.setEducationId(vo.getEducationId());
        }
        if (vo.getIsDel() != 0) {
            info.setIsDel(vo.getIsDel());
        }
        if (vo.getCompusId() != 0) {
            info.setCompusId(vo.getCompusId());
        }
        if (vo.getBranchName() != null) {
            info.setBranchName(vo.getBranchName());
        }
    }
}
